package com.robot.base.view.binding;

import android.graphics.Color;
import android.graphics.Typeface;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;

import androidx.appcompat.widget.SwitchCompat;
import androidx.databinding.BindingAdapter;

import com.robot.base.R;

public class ViewStateBinding {

    @BindingAdapter("android:isSelected")
    public static void isSelected(View view, boolean isSelected) {
        view.setSelected(isSelected);
    }

    @BindingAdapter("android:isChecked")
    public static void isChecked(Switch switchCompat, boolean check){
        switchCompat.setChecked(check);
    }

    @BindingAdapter("android:isGone")
    public static void isGone(View view, boolean isGone) {
        view.setVisibility(isGone ? View.GONE : View.VISIBLE);
    }

    @BindingAdapter("android:setBold")
    public static void setBold(TextView view, boolean isBold){
        view.setTypeface(Typeface.DEFAULT , isBold?Typeface.BOLD:Typeface.NORMAL);
    }
    @BindingAdapter("android:setEnable")
    public static void setEnable(TextView view, boolean isEnable){
        view.setEnabled(isEnable);
    }

    @BindingAdapter("android:setOnHover")
    public static void setOnHover(View view, boolean isSelect){

        view.setOnHoverListener(new View.OnHoverListener() {
            @Override
            public boolean onHover(View v, MotionEvent event) {
                int what = event.getAction();
                switch(what){
                    case MotionEvent.ACTION_HOVER_ENTER: //鼠标进入view
                        System.out.println("bottom ACTION_HOVER_ENTER");
                        view.setBackgroundResource(R.mipmap.ic_back_black);
                        break;
                    case MotionEvent.ACTION_HOVER_MOVE: //鼠标在view上
                        System.out.println("bottom ACTION_HOVER_MOVE");
                        break;
                    case MotionEvent.ACTION_HOVER_EXIT: //鼠标离开view
                        System.out.println("bottom ACTION_HOVER_EXIT");
                        view.setBackgroundColor(Color.TRANSPARENT);
                        break;
                }
                return false;
            }
        });
    }

}
